"""
@name : 8.斐波那契数列
@author : wenyao
@projectname: sanchuanglianxi
"""
#1,1,2,3,5,8,13
#迭代器实现斐波那契数列
class  Fib():
    def __init__(self):
        self.pre = 0
        self.cur = 1

    def __iter__(self):
        #return "ok"
         return self

    def __next__(self):
        result = self.cur
        self.cur += self.pre
        self.pre = result
        return result

f = Fib()
# print(f.__iter__())
# print(iter(f))

#
# f_lst = [next(f) for i in range(20)]
# print(f_lst)


#生成器
# def fib():
#     pre, cur = 0,1
#     while True:
#         yield cur
#         pre, cur = cur, pre+cur
#
# f = fib()
# f_lst = [next(f) for i in range(20)]
# print(f_lst)